<?php

error_reporting(E_ALL);

/**
 * ConexionBD - class.funcAdministra.php
 *
 * $Id$
 *
 * This file is part of ConexionBD.
 *
 * Automatically generated on 27.01.2010, 11:41:36 with ArgoUML PHP module 
 * (last revised $Date: 2008-04-19 08:22:08 +0200 (Sat, 19 Apr 2008) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * include ConexionBD
 *
 * @author Miguel Angel Chavez Obregon
 * @see Funcion con operativas basicas a la base de datos, cualquier metodo que se requiera hacer que no sea directo a la base de datos debera crear una clase que haga extend a esta.
 * @version 1.0
 */
require_once('class.ConexionBD.php');

/**
 * include ssaAdmin
 *
 * @author firstname and lastname of author, <author@example.org>
 */
require_once('interface.ssaAdmin.php');

/* user defined includes */
// section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001040-includes begin
// section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001040-includes end

/* user defined constants */
// section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001040-constants begin
// section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001040-constants end

/**
 * Short description of class funcAdministra
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class funcAdministra
    extends ConexionBD
        implements ssaAdmin
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    // --- OPERATIONS ---

    /**
     * Short description of method guardaAvisos
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int aviso
     * @param  int id_usuario
     * @return void
     */
    public function guardaAvisos($aviso, $id_usuario)
    {
        // section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001045 begin
            $stp=mssql_init("SP_GuardaAvisos",$this->link);
            mssql_bind($stp,'@aviso',$aviso,SQLVARCHAR,false,false,8000);
            mssql_bind($stp,'@id_usuario',$id_usuario,SQLVARCHAR,false,false,10);
            //echo "SP_GuardaAvisos '".$aviso."',".$id_usuario;
            mssql_execute($stp);
            mssql_free_statement($stp);
        // section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001045 end
    }

    /**
     * Short description of method modificaAviso
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int id_aviso
     * @param  int aviso
     * @param  int id_usuario
     * @return void
     */
    public function modificaAviso($id_aviso, $aviso, $id_usuario)
    {
        // section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001049 begin
        // section -64--88-2-12-1500c0df:125de98f646:-8000:0000000000001049 end
    }

    /**
     * Short description of method listaAvisos
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int opcion
     * @return void
     */
    public function listaAvisos($opcion)
    {
        // section -64--88-2-12-1500c0df:125de98f646:-8000:000000000000104E begin
            $stp=mssql_init("SP_avisos",$this->link);
            mssql_bind($stp,'@aviso',$opcion,SQLVARCHAR,false,false,3);
            $result="";
        $resutlSet=mssql_execute($stp);
        While($row=mssql_fetch_object($resutlSet)){
            $result.='<tr align="left">
                         <td>'.$row->fRegistro.'</td>
                         <td>'.$row->aviso.'</td>';
                      if($row->activo==1){
                          $chekedActivo='checked="checked"';
                      }else{
                          $chekedActivo="";
                      }
                      if($row->listado==1){
                          $chekedList="checked";
                      }else{
                          $chekedList="";
                      }
            $result.='<td><input type="checkbox" name="activo_'.$row->id_aviso.'" id="a_'.$row->id_aviso.'" '.$chekedActivo.' value="activo" onclick="actdesa(this.id,'."'generales'".','."'cambiaOpcion.php'".');"></input></td>
                      <td><input type="checkbox" name="Listado_'.$row->id_aviso.'" id="l_'.$row->id_aviso.'" '.$chekedList.'  value="listado" onclick="actdesa(this.id,'."'generales'".','."'cambiaOpcion.php'".');"></input></td></tr>';
        }
          mssql_free_statement($stp);
        return $result;

        // section -64--88-2-12-1500c0df:125de98f646:-8000:000000000000104E end
    }

    /**
     * Short description of method cambioStatus
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int id_aviso
     * @param  int opcion
     * @param  int status
     * @return void
     */
    public function cambioStatus($id_aviso, $opcion, $status)
    {
        // section -64--88-1--47--55fcba5a:125e2658e7d:-8000:0000000000001050 begin
            $stp=mssql_init("SP_cambioSTAviso",$this->link);
            mssql_bind($stp,'@id_aviso',$id_aviso,SQLVARCHAR,false,false,2);
            mssql_bind($stp,'@opcion',$opcion,SQLVARCHAR,false,false,10);
            mssql_bind($stp,'@status',$status,SQLVARCHAR,false,false,2);
            mssql_execute($stp);
            mssql_free_statement($stp);
        // section -64--88-1--47--55fcba5a:125e2658e7d:-8000:0000000000001050 end
    }

    /**
     * Short description of method cmbEstados
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int sp
     * @param  int onChange
     * @param  int status
     * @param  int default
     * @param  int param
     * @return void
     */
    public function cmbEstados($sp, $onChange, $status, $default, $param)
    {
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000108C begin
        return $this->creaCombo("sp_lstEdosDuplicados", "nEstado", "nEstado", $onChange, $status, $default, $param);
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000108C end
    }

    /**
     * Short description of method cmbUSMIS
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int sp
     * @param  int onChange
     * @param  int status
     * @param  int default
     * @param  int param
     * @return void
     */
    public function cmbUSMIS($sp, $onChange, $status, $default, $param)
    {
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:0000000000001093 begin
        return $this->creaCombo("sp_lstUSMISDuplicadas", "cmbUSMIS", "cmbUSMIS", $onChange, $status, $default, $param);
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:0000000000001093 end
    }

    /**
     * Short description of method lstDuplicados
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int id_Estado
     * @param  int id_USMIS
     * @return void
     */
    public function lstDuplicados($id_Estado, $id_USMIS)
    {
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000109A begin
        $stp=mssql_init("sp_lstRegistrosDuplicados",$this->link);
        $param = $id_USMIS."|".$id_Estado;

        mssql_bind($stp,'@param',$param,SQLVARCHAR,false,false,8000);
        //mssql_bind($stp,'@identidad',$id_Estado,SQLINT1,false,false,10);
        $resultSet=mssql_execute($stp);
        $num = mssql_num_fields($resultSet);

        $cadena = "";
        $cadena .= "<table border='1' cellpadding='0' cellspacing='0'>";
        $cadena .= "<tr>";
        $cadena .= "<td class='datos2' align=center>Check</td>";

        for ($x=0;$x<$num;$x++)
            {   $xcampo = mssql_field_name($resultSet, $x);
                $cadena .= "<td class='datos2' align=center><b>$xcampo</b></td>";
            }
        $cadena .= "</tr>";

         while($arr=mssql_fetch_array($resultSet))
            {   $cadena .= "<tr>";
                $cadena .= '<td><input type="checkbox" name="id_'.$arr[0].'" id="id_'.$arr[0].'" value="'.$arr[0].'" onclick="if(confirm('."'¿Esta seguro de que desea eliminar este registro?'".')) { actdesa(this.id,'."'divMsg'".','."'eliminaDupla.php?nEstado=$id_Estado&nUSMIS=$id_USMIS'".')} else { this.checked = false;};"></input></td>';
                for ($x=0;$x<$num;$x++)
                    {   $rot = $arr[$x];
                        $cadena .= "<td class='datos'>".$rot."&nbsp;</td>";
                    }
                $cadena .= "</tr>";
            }
        $cadena .= "</table>";
        mssql_free_statement($stp);
        return $cadena;
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000109A end
    }

    /**
     * Short description of method eliminaRegistro
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int id_general
     * @return void
     */
    public function eliminaRegistro($id_general)
    {
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000109E begin
        $stp=mssql_init("SP_bajaCompleta",$this->link);
        //echo $id_general;
        mssql_bind($stp,'@id_general',$id_general,SQLINT4,false,false,8000);

        $resultSet=mssql_execute($stp);
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:000000000000109E end
    }

    /**
     * Short description of method redNegativa
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int idusuario
     * @return void
     */
    public function redNegativa($idusuario)
    {
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:00000000000010A0 begin
        $stp=mssql_init("sp_InsertaRedNegativa",$this->link);
        //echo $id_general;
        mssql_bind($stp,'@idUsuario',$idusuario,SQLINT4,false,false,8000);

        $resultSet=mssql_execute($stp);

        while($arr=mssql_fetch_array($resultSet))
            {   $cadena = $arr[0];  }

        return $cadena;
        // section 10-16-10-2--55d69bff:126669d7d05:-8000:00000000000010A0 end
    }

    /**
     * Short description of method rptRedNegativa
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  int idInstitucion
     * @param  int idEstado
     * @param  int dtInicial
     * @param  int dtFinal
     * @return void
     */
    public function rptRedNegativa($idInstitucion, $idEstado, $dtInicial, $dtFinal)
    {   // section 10-16-10-2--75174fae:12670d92486:-8000:0000000000001BA4 begin
        if ($dtInicial != "")
            {   $fecha_ini = explode('/',$dtInicial);
                $dtInicial_us = $fecha_ini[1]."/".$fecha_ini[0]."/".$fecha_ini[2];
            }
		else
			{	$dtInicial_us=0;	}
        if ($dtFinal != "")
            {   $fecha_fin = explode('/',$dtFinal);
                $dtFinal_us = $fecha_fin[1]."/".$fecha_fin[0]."/".$fecha_fin[2];
            }
		else
			{	$dtFinal_us=0;	}

        $stp=mssql_init("SP_listaEstados",$this->link);
        mssql_bind($stp,'@param',$idEstado,SQLVARCHAR,false,false,5);
        $resultSet=mssql_execute($stp);
        $num = mssql_num_fields($resultSet);

        $cadena = "";
        $cadena .= "<table border='1' cellpadding='0' cellspacing='0'>";
        $cadena .= "<tr>";
            $cadena .= "<td class='datos2' align=center>Estado</td>";
            $cadena .= "<td class='datos2' align=center>Unidad</td>";
            $cadena .= "<td class='datos2' align=center>Registros</td>";
            $cadena .= "<td class='datos2' align=center>Porcentajes</td>";
            $cadena .= "<td class='datos2' align=center>Requeridos</td>";
        $cadena .= "</tr>";
        $cadena .= "<tr>";

         while($arr=mssql_fetch_array($resultSet))
            {   $cadena .= "<tr>";             
                for ($x=0;$x<$num;$x++)
                    {   $rot = $arr[$x];
                        if ($x!=0)
                            {   $cadena .= "<td class='datos2' align=center><b>$rot</b></td>"; }
                    }
				echo $dtFinal_us;
                $stp1=mssql_init("sp_rptRedNegativa",$this->link);
                mssql_bind($stp1,'@idEntidad',$arr[0],SQLINT4,false,false,5);
                mssql_bind($stp1,'@idSector',$idInstitucion,SQLINT4,false,false,5);
				
                mssql_bind($stp1,'@fInicial',$dtInicial_us,SQLVARCHAR,false,false,10);
                mssql_bind($stp1,'@fTermino',$dtFinal_us,SQLVARCHAR,false,false,10);
				
                $resultSet1=mssql_execute($stp1);
                $num1 = mssql_num_fields($resultSet1);

                while ($arr2=mssql_fetch_array($resultSet1))
                    {   for ($x1=0;$x1<$num1;$x1++)
                            {   $rot1 = $arr2[$x1];
                                if ($x1!=0 || $x1!=2)
                                    {   $cadena .= "<td class='datos2' align=center><b>$rot1</b></td>"; }
                            }
                    }
                mssql_free_statement($stp1);
                $cadena .= "</tr>";
            }
        $cadena .= "</table>";
        mssql_free_statement($stp);
        return $cadena;
        // section 10-16-10-2--75174fae:12670d92486:-8000:0000000000001BA4 end
    }

} /* end of class funcAdministra */

?>